<?php
class mmg_image extends CI_Model{
	var $mgt_image = "mgt_image";

	function __construct()
	{
		parent::__construct();
	}
	
	function setData($id_image,$id_menu,$jenis_image,$upload_image,$deskripsi_image)
	{
		$this->id_image= $id_image;
		$this->id_menu= $id_menu;
		$this->jenis_image= $jenis_image;
		$this->upload_image= $upload_image;
		$this->deskripsi_image= $deskripsi_image;
	}
	
	function setDataUpload($id_image,$upload_image)
	{
		$this->id_image= $id_image;
		$this->upload_image= $upload_image;
	}
	
	function getList($page,$uri_segment){
		$query = $this->db->get($this->mgt_image,$page,$uri_segment);
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}

	function logoList(){
		$this->db->where('jenis_image',"1");
		$query = $this->db->get($this->mgt_image);
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}
	
	function slideList(){
		$this->db->where('jenis_image',"2");
		$query = $this->db->get($this->mgt_image);
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}
	
	function galeryList(){
		$this->db->where('jenis_image',"3");
		$query = $this->db->get($this->mgt_image);
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}
	
	function create()
	{		
		$arrayData = array(
			'id_image'=>$this->id_image,
			'id_menu'=>$this->id_menu,
			'jenis_image'=>$this->jenis_image,
			'upload_image'=>$this->upload_image,
			'deskripsi_image'=>$this->deskripsi_image
		);
		return $this->db->insert($this->mgt_image, $arrayData);
	}
	
	function update($id_image)
	{
		$arrayData = array(
			'id_menu'=>$this->id_menu,
			'jenis_image'=>$this->jenis_image,
			'upload_image'=>$this->upload_image,
			'deskripsi_image'=>$this->deskripsi_image
		);
		$this->db->where('id_image', $id_image);
		return $this->db->update($this->mgt_image, $arrayData);
	}
	
	function updateImage($id_image)
	{
		$arrayData = array(
			'upload_image'=>$this->upload_image
		);
		$this->db->where('id_image', $id_image);
		return $this->db->update($this->mgt_image, $arrayData);
	}
        
	function remove($id_image)
	{
		$this->db->where('id_image', $id_image);
		return $this->db->delete($this->mgt_image);
	}	
	
	function detail($id_image)
	{
		$this->db->where('id_image', $id_image);
		$query = $this->db->get($this->mgt_image);	
		return $query->result_array();
	}
}
?>